package com.neusoft.yuejian_6.adapter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.neusoft.yuejian_6.activity.ActInfoActivity;
import com.neusoft.yuejian_6.R;
import com.neusoft.yuejian_6.javabean.Activity;
import com.squareup.picasso.Picasso;

import java.util.List;



public class ActivityListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{

    private Context mContext;
    private List mDataList;
    private LayoutInflater mLayoutInflater;

    public ActivityListAdapter(Context mContext, List mDataList) {
        this.mContext = mContext;
        this.mDataList = mDataList;
        mLayoutInflater = LayoutInflater.from(mContext);
    }

    @Override
    public int getItemCount() {
        return mDataList.size();
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final Activity entity = (Activity) mDataList.get(position);
        if (null == entity)
            return;
        //绑定数据
        ViewHolder viewHolder = (ViewHolder) holder;
        viewHolder.activity_name.setText(entity.getActivity_name());
        // System.out.printf("activity_name");
        viewHolder.activity_hot.setText(entity.getActivity_hot()+ "");
        String activity_pic ="http://10.0.2.2/neu1_yuejian/Public/Admin/photo/"+entity.getActivity_pic();

        Picasso.with(mContext).load(activity_pic).into(viewHolder.activity_pic);
        if(viewHolder.activity_pic.getDrawable()==null){
            viewHolder.activity_pic.setImageResource(R.drawable.no_pic);
        }
        //点击item跳转
        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Bundle bundle=new Bundle();
                bundle.putInt("activity_id",entity.getActivity_id());
                bundle.putString("activity_name",entity.getActivity_name());
                bundle.putInt("activity_hot",entity.getActivity_hot());
                bundle.putString("activity_pic",entity.getActivity_pic());
                Intent intent=new Intent(mContext, ActInfoActivity.class);
                intent.putExtras(bundle);
                mContext.startActivity(intent);
            }
        });


    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        //创建ViewHolder
        View v = mLayoutInflater.from(parent.getContext()).inflate(R.layout.cardview_acitivty, parent, false);
        return new ViewHolder(v);

    }

    //自定义的V
    public class ViewHolder extends RecyclerView.ViewHolder{
        ImageView activity_pic;
        TextView activity_name,activity_hot;

        public ViewHolder(View itemView) {
            super(itemView);
            activity_name = (TextView) itemView.findViewById(R.id.Activitylist_title);
            activity_pic = (ImageView) itemView.findViewById(R.id.Activitylist_pic);
            activity_hot= (TextView) itemView.findViewById(R.id.hot_count);
        }
    }
}
